package streamAPI.operators;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.co.CoMapFunction;
import streamAPI.source.MyNoParallelSource;

/**
 * @author yue.cao
 * @since 09-28-2020
 */
public class DemoWithConnect {

	public static void main(String[] args) throws Exception {
		StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
		DataStreamSource<Long> stream1 = env.addSource(new MyNoParallelSource());

		DataStream<String> stream2 = stream1.map(new MapFunction<Long, String>() {
			@Override
			public String map(Long in) throws Exception {
				return "Cy " + in;
			}
		});

		stream1.connect(stream2).map(new CoMapFunction<Long, String, String>() {
			@Override
			public String map1(Long value) throws Exception {
				return value.toString();
			}

			@Override
			public String map2(String value) throws Exception {
				return value;
			}
		}).print();

		env.execute();
	}
}
